

 console.log("updateozonfontcate load");
chrome.runtime.onMessage.addListener(async (msg, sender) => {
  console.log(msg)
 getOzonCateByType(msg);

})


function getOzonCateByType(msg){

    var url = "https://www.ozon.ru/product/"+msg.data.item.sku_id;
    var type_id = msg.data.item.type_id;
    console.log("getOzonCateByType:"+url)
    $.ajax({
      url: url,
      method: 'GET',
      dataType: 'html',
      success: function(htmlContent) {
         console.log(htmlContent);
        const dom = $($.parseHTML(htmlContent));
        dom.find('div[id^="state-breadCrumbs-"]').each(function() {
            var body = $(this).attr("data-state");
            var data_state_obj = JSON.parse(body);
            console.log(data_state_obj);
            var type="ozon_font_cate_type_post";
            chrome.runtime.sendMessage({ data: {body,type,type_id}, close: false });
        });
      },
      error: function(xhr, status, error) {
        console.log('Ajax error: ', error);
        if (xhr.status === 403 && status === "error") {
            var type="ozonapi403";
            chrome.runtime.sendMessage({ data: {type}, close: false });
            console.log("遇到了403错误");
             startNextQ();
            //中断
        }
      }
    });

}



